package com.springcloudalibaba.apiAsyn.service;

import com.springcloudalibaba.apiAsyn.entity.BaseFileEntity;
import com.springcloudalibaba.bclass.base.BaseResult;
import com.springcloudalibaba.bclass.base.BaseUploadResult;
import org.springframework.scheduling.annotation.Async;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.CompletableFuture;

/**
 * @description: 文件接口
 * @author: lixing
 * @time: 2021/6/6 12:31
 */
public interface FileService {
    /**
     * @描述 上传文件
     * @作者 lixing
     * @日期 2019/10/4 21:38
     */
    @Async("api-asyn-taskExecutor")
    CompletableFuture<BaseResult<BaseUploadResult>> upload(BaseFileEntity baseEntity);

    /**
     * @描述 下载文件
     * @作者 lixing
     * @日期 2020/12/12 18:50
     */
    void down(BaseFileEntity baseEntity, HttpServletRequest request, HttpServletResponse response) throws Exception;

    /**
     * @描述 上传文件到阿里云OSS
     * @Param inputStream 文件输入流
     * @Param relativePath 上传到阿里云OSS的相对路径，格式：20220606/1603/md.pdf
     * @Return 返回结果为空表示上传失败
     */
    @Async("baseAsynTaskExecutor")
    CompletableFuture<String> uploadFileToAliyunOss(InputStream inputStream, String relativePath);

    /**
     * @描述 从阿里云删除阿里云OSS
     * @param relativePath
     * @return 返回结果为空表示删除失败
     */
    String removeFileToAliyunOss(String relativePath);

    /**
     * @描述 检查文件是否存在于阿里云OSS
     * @param relativePath
     * @return true/false
     */
    boolean doesObjectExist(String relativePath);
}
